<?php

/** 
 * @category		
 * @package		Lib			
 * @subpackage	Action	
 * @author		wanght <whtaok@gmail.com>
 * @since		2013-3-3
 * @version		$Id: AppAction.class.php 12 2013-10-22 08:31:42Z whtaok@gmail.com $
 */

class AppAction extends Action {
	protected $curr_shop_id;
	protected $curr_cust_id;
	protected $page_title='';
	protected $usingModel = '';	
	
	/**
	 * 描述：分页设置
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-5-1
	 */
	public function listPage($model) {
		$nowPage = isset($_REQUEST['p'])?$_REQUEST['p']:1;
		import('ORG.Util.Page');
		$totalRows = $model->count();
		$listRows = 20;
		$pageObj = new Page($totalRows,$listRows);
		$list = $model->page($nowPage,$listRows)->select();
		$page = $pageObj->show();
		$rtn_data = array('list'=>$list,'page'=>$page);
		return $rtn_data;	
	}
	
	/*
	 * 通用是否显示内容
	* */
	public function isShowAct(){
		$id     = intval($_REQUEST['id']);
		$col_name   = trim($_REQUEST['col_name']);
		$data['id'] = $id;
		$data[$col_name] = array('exp',"($col_name+1)%2");
		$model = D($this->usingModel);
		$model->save($data);
		$result = $model->find($id);
		$this->ajaxReturn($result[$col_name]);
	}
	/*
	 * 通用排序方法单个排序
	* */
	public function ordlistAct(){
		$id     = intval($this->_param('id'));
		$col_name  = trim($this->_param('col_name'));
		$col_value =trim($this->_param('col_value'));
		if(!is_numeric($col_value)){
			$model = D($this->usingModel);
			$values = $model->find($id);
			$this->ajaxReturn($values[$col_name]);
		}else{
			$model = D($this->usingModel);
			$data['id'] = $id;
			$data[$col_name] = $col_value;
			$model->save($data);
			$this->ajaxReturn($col_value);
		}
		
	}
	
	/**
	 * 描述：当客户更改账号或登录时刷新session
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected function mysession_refresh($custId){
		//客户信息
		$mod = new CustLibModel();
		$detailCust = $mod->find($custId);
		
		$cust = array(
				'account'=>$detailCust['account'],
				'mobile'=>$detailCust['mobile'],
				'name'=>$detailCust['name'],
				'sex'=>$detailCust['sex'],
				'logo'=>$detailCust['logo'],
				'shop_id'=>$detailCust['shop_id'],
		);
		session(SES_CUST_ID,$custId);
		session(SES_CUST,$cust);
	}
	
	/**
	 * 描述：上传配置文件
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-23
	 */
	protected function doUpload($savapath,$myconfig) {
		$config = array(
				'maxSize'           =>  1024*1000*20,    // 上传文件的最大值为2M
				'supportMulti'      =>  true,    		// 是否支持多文件上传
				'allowExts'         =>  array('gif', 'jpg', 'jpeg', 'png'),    // 允许上传的文件后缀 留空不作后缀检查
				'allowTypes'        =>  array(),    // 允许上传的文件类型 留空不做检查
				'thumb'             =>  true,    // 使用对上传图片进行缩略图处理
				'imageClassPath'    =>  'ORG.Util.Image',    // 图库类包路径
				'thumbMaxWidth'     =>  '240',// 缩略图最大宽度
				'thumbMaxHeight'    =>  '320',// 缩略图最大高度
				'thumbPrefix'       =>  'sml_',// 缩略图前缀
				'thumbSuffix'       =>  '',
				'thumbPath'         =>  '',// 缩略图保存路径
				'thumbFile'         =>  '',// 缩略图文件名
				'thumbExt'          =>  '',// 缩略图扩展名
				'thumbRemoveOrigin' =>  false,// 是否移除原图
				'zipImages'         =>  false,// 压缩图片文件上传
				'autoSub'           =>  false,// 启用子目录保存文件
				'subType'           =>  'hash',// 子目录创建方式 可以使用hash date custom
				'subDir'            =>  '', // 子目录名称 subType为custom方式后有效
				'dateFormat'        =>  'Ymd',
				'hashLevel'         =>  1, // hash的目录层次
				'autoCheck'         =>  true, // 是否自动检查附件
				'uploadReplace'     =>  false,// 存在同名是否覆盖
				'saveRule'          =>  'uniqid',// 上传文件命名规则
				'hashType'          =>  'md5_file',// 上传文件Hash规则函数名
		);
		if($myconfig){
			$config = array_merge($config,$myconfig);
		}
		import("ORG.Net.UploadFile");
		$upload = new UploadFile($config);
		$upload->upload($savapath);
		return $upload;
	}
	
	protected function setPageTitle($title){
		$this->view->page_title = $title;
		$this->assign('page_title',$title);
	}
	
	//获得团购推荐信息
	protected function _showTgProdList(){
		$savePath = C('REALPATH_SHOP').'/tg';
		$tgProdList = F_CACHE($savePath);
		if(is_array($tgProdList)){
			$this->assign('tgProdList',$tgProdList);
		}
	}
	
}

?>